package com.jinzhi.jzapi.examination.task;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jinzhi.jzweb.domain.ExaminationBatchDO;
import com.jinzhi.jzweb.service.ExaminationBatchService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.crypto.Cipher;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;


@Slf4j
@Component
public class AutoTestExaminStateJob implements Job {

    @Autowired
    private ExaminationBatchService examinationBatchService;

    @Override
    @Transactional
    public void execute(JobExecutionContext jobExecutionContext){
        log.info("---------------------开始重置测试考试批次---------------------");
        //查询测试批次
        EntityWrapper<ExaminationBatchDO> ew = new EntityWrapper<ExaminationBatchDO>();
        ew.eq("name","测试批次");
        ExaminationBatchDO examinationBatchDOS = examinationBatchService.selectOne(ew);
        if(examinationBatchDOS != null){
            examinationBatchDOS.setState(6);
            Date now = new Date();
            Calendar start = Calendar.getInstance();
            start.setTime(now);
            // 将时分秒,毫秒域清零
            start.set(Calendar.HOUR_OF_DAY, 8);
            start.set(Calendar.MINUTE, 0);
            start.set(Calendar.SECOND, 0);
            examinationBatchDOS.setStartTime(start.getTime());
            Calendar end = Calendar.getInstance();
            end.setTime(now);
            // 将时分秒,毫秒域清零
            end.set(Calendar.HOUR_OF_DAY, 22);
            end.set(Calendar.MINUTE, 0);
            end.set(Calendar.SECOND, 0);
            examinationBatchDOS.setEndTime(end.getTime());
            examinationBatchService.updateById(examinationBatchDOS);
        }
    }


}
